﻿using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace PlaxoSyncWM {
    public class MobileSettings {
        // returns the Application Startup Path
        public string ApplicationPath() {
            string strPath;
            strPath = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().GetName().CodeBase);
            return strPath;
        }

        public bool settingsFileExists() {
            return File.Exists(string.Format(Constants.PlaxoDataFilePath));
        }

        public bool settingsFileContainsData() {
            string line;
            bool retValue = false;

            try {
                using (FileStream fs = new FileStream(Constants.PlaxoDataFilePath, FileMode.Open, FileAccess.Read)) {
                    StreamReader osr = new StreamReader(fs);
                    while ((line = osr.ReadLine()) != null) {
                        retValue = line.Contains("Username|");
                        osr.Close();
                        return retValue;
                    }
                    fs.Close();
                    fs.Dispose();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, ex.StackTrace);
            }
            return retValue;
        }
    }
}